#!/usr/bin/python3
# -*- coding: UTF-8 -*-
#@软件名称：时间识别删除文件工具
#@作者：冰枫火灵X
#@许可：LGPL v3.1 or later
import os
import time
print('开始运行')
def delvideos(vfile,deldays):
    nowtime=time.time()
    deltime=deldays * 86400
    filetime=os.path.getmtime(vfile)
    if deltime<=nowtime-filetime:
        os.remove(vfile)
        print('已经删除文件：'+vfile)
def find_dir(vdir,deldays2,kzm):
    try:
        for i in os.listdir(vdir):
            if os.path.isfile(vdir+'/'+i):
                if i.split('.')[-1]==kzm:
                    delvideos(vdir+'/'+i,deldays2)
            else:
                print('已经找到子文件夹：'+vdir+'/'+i)
                find_dir(str(vdir+'/'+i),deldays2,kzm)
    except PermissionError as x:
        print('跳过')
if __name__ == '__main__':
    t=int(input('多少天以前：\n'))
    l=str(input('文件扩展名，比如mp4：\n'))
    d=str(input('哪些盘符？留空为defghij：\n'))
    if d != '':
        pan=[]
        for i in d:
            i=i+':/'
            print('加入盘符：'+i)
            pan.append(i)
    elif d == '':
        pan=[]
        for i in 'defghij':
            i=i+':/'
            print('加入盘符：'+i)
            pan.append(i)
    print('已选择路径：')
    print(pan)
    for dirx in pan:
        find_dir(dirx,t,l)
stop=input("运行完毕.")